package com.magenta.maxoptra.gis.distancematrix.builder;

import com.magenta.maxoptra.gis.GeoProviderSettings;
import com.magenta.maxoptra.gis.GeoProviderStatus;
import com.magenta.maxoptra.gis.GeographicCoordinates;
import com.magenta.maxoptra.gis.commons.Pair;
import com.magenta.maxoptra.gis.distancematrix.RoutesIterator;
import com.magenta.maxoptra.gis.distancematrix.UpdateResultType;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author Sergey Grachev
 */
public interface MatrixBuildTaskListener<ID> {
    /**
     * @param groupId as is
     * @return required geo settings or null
     */
    @Nullable
    MatrixBuildTask.Settings onFetchSettings(ID groupId);

    /**
     * @param groupId as is
     * @return required geo settings or null
     */
    @Nullable
    RoutesIterator onFetchCoordinates(ID groupId);

    /**
     * @param settings     early loaded settings of group id
     * @param route        for update
     * @param highPriority should be updated immediately
     * @return current status of provider
     */
    GeoProviderStatus onUpdateRoute(GeoProviderSettings settings,
                                    Pair<? extends GeographicCoordinates, ? extends GeographicCoordinates> route,
                                    boolean highPriority);

    /**
     * @param settings     early loaded settings of group id
     * @param from         start coordinate for all routes
     * @param to           destinations
     * @param highPriority should be updated immediately
     * @return current status of provider
     */
    GeoProviderStatus onUpdateRoute(GeoProviderSettings settings,
                                    GeographicCoordinates from, List<? extends GeographicCoordinates> to,
                                    boolean highPriority);

    /**
     * Check group is active or not
     *
     * @return false if should be ignored
     */
    boolean onCheckIsGroupActive(ID groupId);

    /**
     * All possible routes for coordinate was updated
     */
    void onFinishForCoordinate(ID groupId, GeographicCoordinates coordinate, RoutesIterator.Type routeType,
                               long providerCid, boolean hasErrors);

    /**
     * Group fully updated
     */
    void onFinishGroup(ID groupId, UpdateResultType resultType);

    /**
     * Update progress group
     */
    void onProgress(ID groupId, long total, long progress);
}
